<?php

use yii\helpers\Url;

$web = Url::base();
$scriptUrl = \Yii::$app->request->scriptUrl;

?>

<div class="panel">
    <div class="panel-body">
        <div class="table-responsive">
            <table class="table table-bordered table-hover table-condensed">
                <thead class="nowrap">
                <tr>
                    <th>举报用户</th>
                    <th>举报商家</th>
                    <th>广告标题</th>
                    <th>广告内容</th>
                    <th>广告状态</th>
                    <th>举报时间</th>
                </tr>
                </thead>
                <tbody>
                <?php
                foreach ($items as $item) {
                    ?>
                    <tr>
                        <td><?= $item['user_name'] ?></td>
                        <td><?= $item['merchant_name'] ?></td>
                        <td><?= $item['title'] ?></td>
                        <td><?= $item['content'] ?></td>
                        <td>
                            <?php
                            switch ($item['status']) {
                                case 0:
                                    echo '编辑中';
                                    break;
                                case 10:
                                    echo '提交审核';
                                    break;
                                case 20:
                                    echo '审核通过';
                                    break;
                                case 30:
                                    echo '审核未通过';
                                    break;
                                case 40:
                                    echo '已发布';
                                    break;
                                case 50:
                                    echo '已经开始';
                                    break;
                                case 60:
                                    echo '广告结束';
                                    break;
                            }
                            ?>
                        </td>
                        <td><?= $item['create_datetime'] ?></td>
                        <!--                        <td>-->
                        <!--                            <div class="btn-group">-->
                        <!--                                <a class="btn btn-link" data-toggle="modal" data-id="--><?//= $item['id'] ?><!--"-->
                        <!--                                   href="#detailModal">编辑</a>-->
                        <!--                                <button class="btn btn-link btn-delete-item" data-id="--><?//= $item['id'] ?><!--">发布</button>-->
                        <!--                                <button class="btn btn-link btn-delete-item" data-id="--><?//= $item['id'] ?><!--">删除</button>-->
                        <!--                            </div>-->
                        <!--                        </td>-->
                    </tr>
                    <?php
                }
                ?>
                </tbody>
            </table>
        </div>
        <?= \app\widgets\LinkPagerExt::widget(['pagination' => $pagination]) ?>
    </div>
</div>

<div aria-hidden="true" role="dialog" tabindex="-1" id="detailModal" class="modal fade">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button aria-hidden="true" data-dismiss="modal" class="close" type="button">×</button>
                <h4 class="modal-title">广告</h4>
            </div>
            <div class="modal-body" id="detail_content">
                正在加载数据....
            </div>
            <div class="modal-footer">
                <button class="btn btn-default" data-dismiss="modal">关闭</button>
                <button class="btn btn-primary" id="btnAddOk">确定</button>
            </div>
        </div>
    </div>
</div>

<script type="application/javascript">
    (function () {

        $('#btnAddOk').click(function () {
//            var data = {};
//            data.id = $('#hiddenId').val();
//            data.merchant_id = '0';
//            data.industry_type_id = $("#inputIndustryType").find("option:selected").val();
//            data.title = $('#inputTitle').val().trim();
//            data.content = $('#inputContent').val().trim();
//            data.status = 0;
//            requestJson('ad-save-handler', {data: data}, true, function (responseData) {
//                if (responseData.status == 0) {
//                    window.location.reload();
//                }
//            })

            $("#ad_detail_partial_form").submit();
            $("#ad_detail_partial_form_target").load(function () {
                try {
                    var result = JSON.parse($("#ad_detail_partial_form_target").contents().find("body").html());
                    if (result.status == 0) {
                        window.location.reload();
//                        filter();
//                        $("#imageList").modal('hide');
                    } else {
                        alert(result.message);
                    }
                } catch (err) {
                    alert("保存出错");
                }
            })
        });

        $('#detailModal').on('show.bs.modal', function (e) {
            $("#detail_content").html('正在加载数据....');
            var id = e.relatedTarget.attributes['data-id'].value;
            requestHtml('ad-detail-partial', {id: id}, true, function (responseHtml) {
                $("#detail_content").html(responseHtml);
            });
        });

        $('.btn-delete-item').click(function () {
            var result = confirm('是否确认删除此广告?');
            if (result == true) {
                var id = $(this).attr('data-id');
                requestJson('ad-delete-handler', {'id': id}, true, function (responseData) {
                    if (responseData.status == 0) {
                        window.location.reload();
                    }
                });
            }
        });

    })(jQuery);

    //设置模态窗:当用户点击模态框外部时不会关闭、当初始化时不显示模态框。
    $(function () {
        $('#addModal').modal({
            backdrop: 'static', show: false
        });

        $('#detailModal').modal({
            backdrop: 'static', show: false
        });

    });
</script>
